//
//  PublishCell.m
//  soccer
//
//  Created by 上官千城 on 15/9/7.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "PublishCell.h"

@implementation PublishCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self && [reuseIdentifier isEqualToString:@"settingCell"]) {
        [self creatCell];
    }
    if (self && [reuseIdentifier isEqualToString:@"textCell"]) {
        [self creatTextField];
    }
    if (self && [reuseIdentifier isEqualToString:@"publishCell"]) {
        [self creatPublish];
    }
    return self;
}
//3区
-(void)creatPublish
{
    self.publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.publishButton.frame = CGRectMake(10, 10, WIDTH-20, 30);
    [self.publishButton setTitle:@"确认发布" forState:UIControlStateNormal];
    [self.publishButton addTarget:self action:@selector(pulishiAction) forControlEvents:UIControlEventTouchUpInside];
    self.publishButton.layer.masksToBounds = YES;
    self.publishButton.layer.cornerRadius = 5;
    self.publishButton.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:self.publishButton];
}
//2区
-(void)creatTextField
{
    self.text = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, WIDTH - 20 , 180)];
    self.text.placeholder = @"请输入此刻的想法";
    //边框
    self.text.borderStyle = UITextBorderStyleRoundedRect;
    self.text.adjustsFontSizeToFitWidth = NO;
    self.text.textAlignment = NSTextAlignmentJustified;
    self.text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;  //垂直居中
    [self.contentView addSubview:self.text];
}

//1区
-(void)creatCell
{
    self.addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.addButton.frame = CGRectMake(10, 10, 70, 70);
    [self.addButton setImage:[UIImage imageNamed:@"添加图片@2x"] forState:UIControlStateNormal];
    [self.addButton addTarget:self action:@selector(addPicAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.addButton];
    
    self.soundButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.soundButton.frame = CGRectMake(self.addButton.frame.origin.x + self.addButton.frame.size.width + 10, self.addButton.frame.origin.y, self.addButton.frame.size.width, self.addButton.frame.size.height);
    [self.soundButton setImage:[UIImage imageNamed:@"添加录音"] forState:UIControlStateNormal];
    [self.soundButton addTarget:self action:@selector(soundButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.soundButton];
    
}
//添加语音
-(void)soundButtonAction
{
    NSLog(@"语音");
}
//添加图片
-(void)addPicAction
{
    [self.myDelegate pushPhoto];
}

//3区发布方法
-(void)pulishiAction
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"确认要发布么?" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
    [alert show];
    
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0) {
        NSLog(@"是");
    }
    else if (buttonIndex == 1)
    {
        NSLog(@"否");
    }
}


@end
